package com.jcroke.DACGraph;

import org.apache.commons.io.IOUtils;

/**
 * @author jcroke
 *
 */

public class SPARQL {

	public static final String PREAMBLE = "prefix rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#>"
			+ IOUtils.LINE_SEPARATOR
			+ "prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>"
			+ IOUtils.LINE_SEPARATOR
			+ "prefix owl:  <http://www.w3.org/2002/07/owl#>"
			+ IOUtils.LINE_SEPARATOR
			+ "prefix xsd:  <http://www.w3.org/2001/XMLSchema#>"
			+ IOUtils.LINE_SEPARATOR
			+ "prefix dc:    <http://purl.org/dc/elements/1.1/>"
			+ IOUtils.LINE_SEPARATOR
			+ "prefix rr:   <http://www.w3.org/ns/r2rml#>"
			+ IOUtils.LINE_SEPARATOR
			+ "prefix pc3:  <http://pc3.nokia.com/schemata/pc3#>"
			+ IOUtils.LINE_SEPARATOR;

	public static final String FIELD_VARIABLE = "bolt";

	public static final String BOUNDARY_NODE_QUERY_TEMPLATE = PREAMBLE
			+ IOUtils.LINE_SEPARATOR + "select ?bolt" + IOUtils.LINE_SEPARATOR
			+ "    where { " + IOUtils.LINE_SEPARATOR
			+ " ?dataset a pc3:dataset ." + IOUtils.LINE_SEPARATOR
			+ " ?dataset pc3:name \"%s\" ." + IOUtils.LINE_SEPARATOR
			+ " ?dataset pc3:boundarySet ?bs ." + IOUtils.LINE_SEPARATOR
			+ " ?bs a pc3:boundarySet ." + IOUtils.LINE_SEPARATOR
			+ " ?bs pc3:boltOrder ?bolts ." + IOUtils.LINE_SEPARATOR
			+ " ?bolts rdf:rest*/rdf:first ?bolt" + IOUtils.LINE_SEPARATOR
			+ "}";

	public static final String WIRE_DESCRIPTION_QUERY_TEMPLATE = PREAMBLE
			+ IOUtils.LINE_SEPARATOR + "select ?name ?type ?typeClass ?bolt ?subscription"
			+ IOUtils.LINE_SEPARATOR + "    where { " + IOUtils.LINE_SEPARATOR
			+ "bind (<%s> as ?wire) ." + IOUtils.LINE_SEPARATOR
			+ "?wire a pc3:wire ." + IOUtils.LINE_SEPARATOR
			+ "?wire pc3:name ?name ." + IOUtils.LINE_SEPARATOR
			+ "?wire pc3:type ?type ." + IOUtils.LINE_SEPARATOR
			+ "?type a pc3:type ." + IOUtils.LINE_SEPARATOR
			+ "?type pc3:class ?typeClass ." + IOUtils.LINE_SEPARATOR
			+ "?wire pc3:outputCollector ?pinOuts ." + IOUtils.LINE_SEPARATOR
			+ "?pinOuts rdf:rest*/rdf:first ?pinOut ." + IOUtils.LINE_SEPARATOR
			+ "?pinOut pc3:outputField ?subscription ."+ IOUtils.LINE_SEPARATOR
			+ IOUtils.LINE_SEPARATOR + "?pinOut pc3:bolt ?bolt"
			+ IOUtils.LINE_SEPARATOR + "}";

	public static final String BOLT_WIRE_QUERY_TEMPLATE = PREAMBLE
			+ IOUtils.LINE_SEPARATOR + "select ?name ?input ?wire"
			+ IOUtils.LINE_SEPARATOR + "    where { " + IOUtils.LINE_SEPARATOR
			+ "bind (<%s> as ?bolt) ." + IOUtils.LINE_SEPARATOR
			+ "?bolt a pc3:bolt ." + IOUtils.LINE_SEPARATOR
			+ "?bolt pc3:name ?name ." + IOUtils.LINE_SEPARATOR
			+ "?bolt pc3:inputConnections ?connections ."
			+ IOUtils.LINE_SEPARATOR
			+ "?connections rdf:rest*/rdf:first ?connection ."
			+ IOUtils.LINE_SEPARATOR + "?connection pc3:pin ?input ."
			+ IOUtils.LINE_SEPARATOR + "?connection pc3:wire ?wire ."
			+ IOUtils.LINE_SEPARATOR + "}";

	public static final String BOLT_LOGIC_QUERY_TEMPLATE = PREAMBLE
			+ IOUtils.LINE_SEPARATOR + "select ?name ?value ?logic"
			+ IOUtils.LINE_SEPARATOR + "    where { " + IOUtils.LINE_SEPARATOR
			+ "bind (<%s> as ?bolt) ." + IOUtils.LINE_SEPARATOR
			+ "?bolt a pc3:bolt ." + IOUtils.LINE_SEPARATOR
			+ "?bolt pc3:name ?name ." + IOUtils.LINE_SEPARATOR
			+ "optional {?bolt pc3:value ?value ." + IOUtils.LINE_SEPARATOR
			+ "}" + IOUtils.LINE_SEPARATOR
			+ "optional { ?bolt pc3:execute ?logic" + IOUtils.LINE_SEPARATOR
			+ "}" + IOUtils.LINE_SEPARATOR + "}";

	public static final String CLASS_LOGIC_QUERY_TEMPLATE = PREAMBLE
			+ IOUtils.LINE_SEPARATOR
			+ "select ?name ?class ?code ?import ?throw"
			+ IOUtils.LINE_SEPARATOR + "    where { " + IOUtils.LINE_SEPARATOR
			+ "bind (<%s> as ?logic) ." + IOUtils.LINE_SEPARATOR
			+ "?logic a pc3:logic ." + IOUtils.LINE_SEPARATOR
			+ "?logic pc3:name ?name ." + IOUtils.LINE_SEPARATOR
			+ "optional { ?logic pc3:className ?class } ."
			+ IOUtils.LINE_SEPARATOR + "optional { ?logic pc3:codeBody ?code ."
			+ IOUtils.LINE_SEPARATOR + "?logic pc3:codeImport ?import ."
			+ IOUtils.LINE_SEPARATOR + "?logic pc3:codeThrow ?throw ."
			+ IOUtils.LINE_SEPARATOR + "}" + IOUtils.LINE_SEPARATOR + "}";

}
